import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
};

export const constantRoutes = [
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/Login.vue"),
    hidden: true
  },
  {
    path: "/register",
    name: "Register",
    component: () => import("@/views/Register.vue"),
    hidden: true
  },
  {
    path: "/",
    name: "Index",
    component: () => import("@/views/Index.vue")
  },
  {
    path: "/document",
    name: "Document",
    component: () => import("@/views/Document.vue")
  }
];

const router = new VueRouter({
  scrollBehavior: () => ({ y: 0 }),
  //mode: "history",
  base: process.env.BASE_URL,
  routes: constantRoutes
});

export default router;
